Completed
Branch master (6959b7)
by Pieter Epeüs
22:59 queued 19:07
created

error.spec.js ➔ testWrongInput   A

Complexity

Conditions 3

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 3
1
import Gate from '../../src/LogicGates.mjs';
2
import InvalidInputError from '../../src/InvalidInputError';
3
4
const ErrorTestCases = [
5
    {
6
        description: 'test inputs with a null value',
7
        inputs: null,
8
        expectedError: 'inputs isnt a array of booleans',
9
    },
10
    {
11
        description: 'test inputs with a string',
12
        inputs: 'not ok',
13
        expectedError: 'inputs isnt a array of booleans',
14
    },
15
    {
16
        description: 'test inputs with a string',
17
        inputs: [true, 42],
18
        expectedError: 'inputs isnt a array of booleans',
19
    },
20
    {
21
        description: 'test inputs with a string',
22
        inputs: [1],
23
        expectedError: 'inputs isnt a array of booleans',
24
    },
25
    {
26
        description: 'test inputs with a string',
27
        inputs: [0],
28
        expectedError: 'inputs isnt a array of booleans',
29
    },
30
    {
31
        description: 'test inputs with a string',
32
        inputs: [null],
33
        expectedError: 'inputs isnt a array of booleans',
34
    },
35
];
36
37
describe.each(ErrorTestCases)(
38
    'Test totalTrueInputs helper exception test',
39
    ({ description, inputs, expectedError }) => {
40
        it(description, () => {
41
            function testWrongInput() {
42
                Gate.create(inputs);
43
            }
44
45
            expect(testWrongInput).toThrowError(new Error(expectedError));
46
            expect(testWrongInput).toThrowError(InvalidInputError);
47
        });
48
    }
49
);
50